package com.notes.algo.sx;

public class Solution4 {
	public static void main(String[] args) {
		java.util.Scanner sc = new java.util.Scanner(java.lang.System.in);
        String mStr = sc.next();
        String mRule = sc.next();
        boolean isMatch = isMatch(mStr, mRule);
        System.out.println(isMatch);
	}

	public static boolean isMatch(String mStr, String mRule) {
		int lenS = mStr.length();
		int lenR = mRule.length();
		boolean[][] result = new boolean[lenS + 1][lenR + 1];
		result[0][0] = true;
		for (int i = 1; i <= lenR; ++ i) {
			if (mRule.charAt(i - 1) == '*') {
				result[0][i] = true;
			} else {
				break;
			}
		}

		for (int i = 1; i <= lenS; ++ i) {
			for (int j = 1; j <= lenR; ++ j) {
				if (mRule.charAt(j - 1) == '*') {
					result[i][j] = result[i - 1][j] || result[i][j - 1];
				} else if (mRule.charAt(j -1) == '?' || mStr.charAt(i - 1) == mRule.charAt(j -1)) {
					result[i][j] = result[i - 1][j - 1];
 				}
			}
		}

		return result[lenS][lenR];
	}
}
